import {
    getdiseaseList
} from "@/api/department";
export default {
    props: {
        code: {
            type: Number,
            default: undefined,
        },
        isDisabled: {
            type: Boolean,
            default: false,
        },
        placeholder: {
            type: String,
            default: "请选择",
        },
        diseaseList1: {
            type: Array,
            default: () => {
                return [];
            },
        },
    },
    components: {},
    data() {
        return {
            num: 0,
            diseaseList: [], //病种列表
            loading: false,//加载中
        }
    },
    watch: {
        code(val) {
            this.diseaseCodes = this.code;
        },
        diseaseList1(val) {
            this.diseaseList = val;
            if (val.length == 0) {
                this.num = this.num + 1;
                if (this.num > 5) return;
                this.getDiseaseList(); //获取科室对应病种
            }
        },
    },
    computed: {
        dpInfo() {
            let dpInfo = this.$util.getItem("dpInfo");
            dpInfo = dpInfo ? JSON.parse(dpInfo) : {};
            return dpInfo;
        }
    },
    methods: {
        //获取疾病列表
        getDiseaseList() {
            let data = {
                page: 1,
                limit: 999,
                domain:this.dpInfo.domain||""
            };
            getdiseaseList(data)
                .then((res) => {
                    this.loading = false;
                    if (res.code == 200 && res.data) {
                        let arr = [];
                        res.data.records.map((item) => {
                            arr.push({
                                value: item.code,
                                label: item.name,
                            });
                        });
                        this.diseaseList = arr;
                        this.diseaseCodes = this.code;
                        this.$emit("handelDiseaseList", this.diseaseList);
                    }
                })
                .finally(() => { });
        },
        reset() {
            this.diseaseCodes = [];
        },
        handelEvent(value) {
            this.$emit("handelEvent", value);
        },
        //远程搜索
        remoteMethod(query) {
            console.log(query)
            if (query !== '') {
                this.loading = true;
                this.getDiseaseList(query)
            } else {
                console.log('清空')
                this.diseaseList = [];
            }
        }
    },
    created() {
        this.diseaseList = this.diseaseList1;
        this.diseaseCodes = this.code;
        if (this.diseaseList.length == 0) {
            this.num = this.num + 1;
            if (this.num > 5) return;
            this.getDiseaseList(); //获取科室对应病种
        }
    },
}